<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .parent {
            width: 500px;
            height: 400px;
            border: 1px solid red;
            /* 容器水平居中 */
            margin: 0 auto;
            /* 设置弹性盒 
给父元素设置弹性盒后 子元素成为叹息元素 弹性元素沿着主轴方向排列
*/
            display: flex;
            /* 更改主轴排列方向  默认row水平 column垂直*/
            flex-direction: row;
            /* 当弹性元素宽度超过父容器宽度 会等比例压缩 */
            /* 更改弹性元素主轴 */
            justify-content: center;
            align-items: center;
        }

        .child {
            width: 100px;
            height: 60px;
            color: white;
        }
    </style>
</head>

<body>
    <div class="parent">
        <div class="child" style="background-color: red;">弹性元素1</div>
        <div class="child" style="background-color: green;">弹性元素2</div>
        <div class="child" style="background-color: blue;">弹性元素3</div>
        <div class="child" style="background-color: red;">弹性元素1</div>
        <div class="child" style="background-color: green;">弹性元素2</div>
        <div class="child" style="background-color: blue;">弹性元素3</div>
    </div>
</body>

</html>